package authorizedService

import (
	"gitee.com/yangguoliang001/go-gin-vue3/QO"
	"gitee.com/yangguoliang001/go-gin-vue3/dao/authorizedDao"
	"gitee.com/yangguoliang001/go-gin-vue3/model"
	"gitee.com/yangguoliang001/go-gin-vue3/vo"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v7"
	"gorm.io/gorm"

	"go.uber.org/zap"
)

type AuthorizedService interface {
	QueryAuthList(c *gin.Context, authReq QO.AuthorizedListReq) (authListRes vo.AuthorizedListVO, err error)
	AddAuthorized(c *gin.Context, authReq QO.AddAuthorizedReq) (err error)
	UpdateAuthorized(c *gin.Context, authReq QO.UpdateAuthorizedReq) (err error)
	DeleteAuthorized(c *gin.Context, id int) (err error)

	QueryAuthApiList(c *gin.Context, businessKey string) (res vo.AuthAPiVO, err error)
	AddAuthorizedApi(c *gin.Context, apiReq QO.AddAuthApiReq) (apiItem model.AuthorizedApiDO, err error)
	DeleteAuthorizedApi(c *gin.Context, id string) (err error)
}

type authorizedService struct {
	logger        *zap.Logger
	cache         *redis.Client
	authorizedDao authorizedDao.AuthorizedDao
}

func New(db *gorm.DB, cache *redis.Client, logger *zap.Logger) AuthorizedService {
	return &authorizedService{
		logger:        logger,
		cache:         cache,
		authorizedDao: authorizedDao.New(db),
	}
}
